package com.stars.empoly.adapter

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.text.TextUtils
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.R
import com.stars.empoly.databinding.ItemPeopleinfoBinding
import com.stars.empoly.model.DataInfoBean
import com.yanzhenjie.permission.Action
import com.yanzhenjie.permission.AndPermission
import com.trailer.base.base.BAdapter
import com.trailer.base.model.PositionBean

class OrderInfoadapter(var list: ArrayList<PositionBean>, var isShow: Boolean) : BAdapter<DataInfoBean.OrderBean.SendBean,
        BaseDataBindingHolder<ItemPeopleinfoBinding>>(R.layout.item_peopleinfo) {
    @SuppressLint("WrongConstant")
    override fun convert(holder: BaseDataBindingHolder<ItemPeopleinfoBinding>, item: DataInfoBean.OrderBean.SendBean) {
        holder.dataBinding?.item = item
        holder.dataBinding?.isShow = isShow


        holder.dataBinding?.tvPhone!!.onClick {

            //拨打电话
            if (TextUtils.isEmpty(item.mobile)) {
                toast("未添加电话！！")
                return@onClick
            }
            AndPermission.with(context)
                    .runtime()
                    .permission(Manifest.permission.CALL_PHONE)
                    .onGranted(Action<List<String?>?> {
                        val intent = Intent(Intent.ACTION_DIAL)
                        val uri = Uri.parse("tel:$item.mobile")
                        intent.data = uri
                        context!!.startActivity(intent)
                    }).start()

        }

    }
}
